package metaphor.service.spring;
/*
 *  Copyright 2008 Mark Ashworth <javameme@gmail.com>.
 * 
 *  Licensed under the GNU General Public License v3 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 * 
 *       http://www.gnu.org/licenses/gpl-3.0.html
 * 
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *  under the License.
 */
import metaphor.service.ApplicationManager;
import metaphor.service.BeanNames;
import metaphor.service.ServiceException;
import metaphor.service.AbstractApplicationManager;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

/**
 * Spring Application Manager
 * @author Mark Ashworth <javameme@gmail.com>
 * @version 1.0.0
 * @since 1.0.0
 */
public class SpringApplicationManager extends AbstractApplicationManager implements ApplicationContextAware {
    /** Spring application context */
    protected ApplicationContext applicationContext;

    public ApplicationContext getApplicationContext() {
        return applicationContext;
    }

    public void setApplicationContext(ApplicationContext applicationContext) {
        this.applicationContext = applicationContext;
    }

    public Object getDao() throws ServiceException {
        return getBean(getDaoName(), getDaoClass());
    }

    /**
     * Returns the security manager
     * @return Security Manager
     * @throws ServiceException If the security manager could not be loaded
     */
    public metaphor.service.SecurityManager getSecurityManager() throws ServiceException {
        return (metaphor.service.SecurityManager) getBean(getSecurityManagerName(), getSecurityManagerClass());
    }

    public Object getBean(String name) {
        return this.applicationContext.getBean(name);
    }

    public Object getBean(String name, Class beanClass) {
        return this.applicationContext.getBean(name, beanClass);
    }
}
